package com.le.tester.webpage.periodCallback;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述：周期性回调
 */
public class PeriodicCallback extends Thread {

    List<Callback<LocalDateTime>> callbackTimes = new ArrayList<>();

    @Override
    public void run() {
        int i = 0;
        try {
            while (i < 10) {
                doRun();
                System.out.println("current thread name is " + Thread.currentThread().getName() + " and i is " + i);
                Thread.sleep(1000);
                i++;
            }
            System.out.println("回调结束");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void doRun() {
        for (Callback<LocalDateTime> callbackItem : callbackTimes) {
            callbackItem.callback(LocalDateTime.now());
        }
    }
}
